package com.leetCode.solution1;

public class Solution2 {
    public ListNode removeElements(ListNode head, int val) {
        /* 虚拟头结点 */
        ListNode dummyHead = new ListNode(-1);
        dummyHead.next = head;

        ListNode pre = dummyHead;

        while (pre.next != null) {
            if (pre.next.val == val) {
                pre.next = pre.next.next;
            }else{
                pre = pre.next;
            }
        }
        return head;
    }
}
